package com.liuzu.esys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liuzu.esys.common.LayuiPageVo;
import com.liuzu.esys.mapper.AftersaleMapper;
import com.liuzu.esys.pojo.Aftersale;
import com.liuzu.esys.service.AftersaleService;
import com.liuzu.esys.vo.YyhPieVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Description :天干物燥，小心火烛
 * @Author : yyh
 * @Date : 2022/07/25 15:03:51
 * @desc
 */
@Service("aftersaleService")
public class AftersaleServiceImpl implements AftersaleService {
    @Autowired
    private AftersaleMapper aftersaleMapper;
    @Override
    public int addAftersale(Aftersale aftersale) {
        int i =aftersaleMapper.addAftersale(aftersale);
        return i;
    }

    @Override
    public int updateAftersale(Aftersale aftersale) {
        return aftersaleMapper.updateAftersale(aftersale);
    }

    @Override
    public int deleteAftersale(Integer id) {
        return aftersaleMapper.deleteAftersale(id);
    }

    @Override
    public LayuiPageVo<Aftersale> aftersalePageData(Map<String, Object> params) {
        // mybatis 的 分页插件
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page, limit);
        List<Aftersale> aftersales = aftersaleMapper.selectByParams(params);
        // mybatis 的 分页数据结构
        PageInfo<Aftersale> aftersalePageInfo = new PageInfo<>(aftersales);
        //把mybatis 的 分页数据 封装到  layui 的分页数据结构中
        LayuiPageVo<Aftersale> aftersaleLayuiPageVo = new LayuiPageVo<>();
        aftersaleLayuiPageVo.setCode(0);  // layui 默认 0 是正确的状态码
        aftersaleLayuiPageVo.setMsg("分页列表数据"); // 提示信息
        aftersaleLayuiPageVo.setCount(aftersalePageInfo.getTotal()); // 总记录数
        aftersaleLayuiPageVo.setData(aftersalePageInfo.getList());  // 分页的列表数据
        return aftersaleLayuiPageVo;
    }

    @Override
    public List<YyhPieVo> statePieData() {
        List<YyhPieVo> list = aftersaleMapper.statePieData();
        return list;
    }
}
